const webpack = require('webpack')
const server = require('./server')
const wpServerCfg = require('./webpack.server.js')

function packServer() {
  console.log('packServer')
  return new Promise((resolve, reject) => {
    webpack(wpServerCfg, (err, stats) => {
      if (err === null && stats.compilation.errors.length === 0) {
        console.log('编译成功')
        resolve(true)
      } else {
        console.log('编译出现错误...')
        console.log(stats.compilation.errors[0].message)
        /* eslint-disable no-new */
        // reject(false)
      }
    })
  })
}

Promise
  .all([packServer()])
  .then(() => {
    console.log('Client/Server全部编译成功！')
    server()
  })
